package com.kanqiubao.kq.activity.recoding;

import android.os.Bundle;

import com.kanqiubao.kq.R;
import com.kanqiubao.kq.activity.BaseActivity;
import com.kanqiubao.kq.adapter.main.RecodingListAdapter;
import com.kanqiubao.kq.adapter.recoding.RecodingDayListAdapter;
import com.kanqiubao.kq.fragment.NewsFragmentStatePagerAdapter;
import com.kanqiubao.kq.fragment.recoding.RecodingDayPageFragment;
import com.kanqiubao.kq.utils.AppConfig;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

/**
 * 录像选择日期
 */
public class RecodingSelectDayActivity extends BaseActivity<String> {


    private ViewPager mViewPager;
    private ArrayList<Fragment> fragments;
    private NewsFragmentStatePagerAdapter mNewsFragmentStatePagerAdapter;

    @Override
    protected void onActivityCreate(Bundle savedInstanceState) {
        mViewPager = findView(R.id.page_id);
        getAllMonth();
    }

    @Override
    protected int getActivitylayout() {
        return R.layout.recoding_sc_page_main_layout;
    }

    @Override
    protected String getTitleText() {
        return "赛程日历";
    }

    private void getAllMonth() {
        String[] s = new String[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
        int current = AppConfig.getCurrentYear();//当前年份
        int cmonth = AppConfig.getCurrentMoth();
        int cday = AppConfig.getCurrentMonthDay();
        List<String> allMonth = new ArrayList<>();
        for (int i = current - 5; i <= current; i++) {//过去5年的数据
            for (int j = 0; j < s.length; j++) {
                if (i == current && j == cmonth) {//添加到当前月就可以了
                    break;
                }
                allMonth.add(i + "," + s[j]);
            }
        }
        fragments = new ArrayList<>();
        for (int i = 0; i < allMonth.size(); i++) {
            RecodingDayPageFragment item = new RecodingDayPageFragment();
            item.setmTitle(allMonth.get(i));
            fragments.add(item);
        }
        mViewPager.setOffscreenPageLimit(5);
        mNewsFragmentStatePagerAdapter = new NewsFragmentStatePagerAdapter(getSupportFragmentManager(), fragments);
        mViewPager.setAdapter(mNewsFragmentStatePagerAdapter);
        mViewPager.setCurrentItem(fragments.size());//选中最后一个
    }
}
